package com.shouhuobao.take.active.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shouhuobao.station.R;
import com.shouhuobao.take.model.ActiveRankListBean;
import com.shouhuobao.take.utils.StringUtils;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;

/**
 * Created by joker on 2017/9/21.
 * 活动榜单名次适配器
 */
public class ActiveRankListAdapter extends BaseAdapterExt<ActiveRankListBean.RankListBean> {

    public ActiveRankListAdapter(ArrayList<ActiveRankListBean.RankListBean> items, Activity context) {
        super(items, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_active_list, parent, false);
            holder.rankingTV = (TextView) convertView.findViewById(R.id.ranking_tv);
            holder.storeNameTV = (TextView) convertView.findViewById(R.id.store_name_tv);
            holder.parcelNum_TV = (TextView) convertView.findViewById(R.id.parcel_num_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final ActiveRankListBean.RankListBean item = items.get(position);
        String parcelCountStr = item.getParcelCount();
        if (StringUtils.isEmpty(parcelCountStr)) {
            parcelCountStr = "0个";
        }
        if (position == 0) {//一等奖
            holder.rankingTV.setTextColor(Color.parseColor("#FF3939"));
            holder.storeNameTV.setTextColor(Color.parseColor("#FF3939"));
            holder.parcelNum_TV.setTextColor(Color.parseColor("#FF3939"));
        } else if (position == 1) {//二等奖
            holder.rankingTV.setTextColor(Color.parseColor("#F5A623"));
            holder.storeNameTV.setTextColor(Color.parseColor("#F5A623"));
            holder.parcelNum_TV.setTextColor(Color.parseColor("#F5A623"));
        } else if (position == 2) {//三等奖
            holder.rankingTV.setTextColor(context.getResources().getColor(R.color.app_font_blue));
            holder.storeNameTV.setTextColor(context.getResources().getColor(R.color.app_font_blue));
            holder.parcelNum_TV.setTextColor(context.getResources().getColor(R.color.app_font_blue));
        } else {//其他
            holder.rankingTV.setTextColor(context.getResources().getColor(R.color.app_font));
            holder.storeNameTV.setTextColor(context.getResources().getColor(R.color.app_font));
            holder.parcelNum_TV.setTextColor(context.getResources().getColor(R.color.app_font));
        }
        holder.rankingTV.setText(item.getRank());
        holder.storeNameTV.setText(item.getStationName());
        holder.parcelNum_TV.setText(parcelCountStr);
        return convertView;
    }

    private class ViewHolder {
        TextView rankingTV;//名次
        TextView storeNameTV;//店铺名字
        TextView parcelNum_TV;//包裹数量
    }
}
